package com.yoomiito.app.widget.dialog;

import android.content.Context;
import androidx.annotation.NonNull;
import android.text.InputFilter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.utils.NumInputFilter;
import com.yoomiito.app.utils.YMToast;

public class InputNumDialog extends BaseDialog {
    private EditText mNumEt;
    private OnNumChangeListener mOnNumChangeListener;

    public InputNumDialog(@NonNull Context context) {
        super(context, R.style.dialog_2);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_input_num,null,false);
        mNumEt = view.findViewById(R.id.num_et);
        NumInputFilter numInputFilter =new NumInputFilter();
        numInputFilter.addNumResultListener(result -> YMToast.showText(result));
        mNumEt.setFilters(new InputFilter[]{numInputFilter});
        TextView sureTv = view.findViewById(R.id.item_sure);
        sureTv.setText("确定");
        sureTv.setOnClickListener(v -> {
            dismiss();
            if (mOnNumChangeListener!=null)mOnNumChangeListener.result(mNumEt.getText().toString());
        });
        view.findViewById(R.id.item_cancel).setOnClickListener(v -> dismiss());
        setmGravity(Gravity.CENTER);
        setWidthPercent(0.75);
        setCanceledOnTouchOutside(true);
        return view;
    }

    public void addOnNumChangeListener(OnNumChangeListener onNumChangeListener) {
        mOnNumChangeListener = onNumChangeListener;
    }

    public interface OnNumChangeListener{
        void result(String num);
    }
}
